package com.acme.task1;

/**
 * This class calculate result of arithmetic operation of two operands
 * 
 * @author Anton Kotov
 */
public class Calculator {
	/**
	 * This method simply print usage string to System.out and terminates the
	 * program
	 */
	private static void printUsage() {
		System.out.format("usage: %s <double> <operation> <double>%n"
				+ "where: <double> - real number and <operation> - [+-*/]%n",
				Calculator.class.getName());
		System.exit(1);
	}

	/**
	 * Main method
	 * 
	 * @param args
	 *            command line arguments (for example: 2 + 3). Note! For
	 *            multiplication you should write: 4 "*" 5
	 */
	public static void main(String[] args) {
		if (args.length < 3) {
			printUsage();
		}

		try {
			double op1 = Double.parseDouble(args[0]);
			double op2 = Double.parseDouble(args[2]);
			double res = 0.0;

			switch (args[1]) {
			case "+":
				res = op1 + op2;
				break;
			case "-":
				res = op1 - op2;
				break;
			case "*":
				res = op1 * op2;
				break;
			case "/":
				res = op1 / op2;
				break;
			default:
				printUsage();
				break;
			}

			System.out.println(res);

		} catch (NumberFormatException e) {
			System.out.println(e.toString());
			printUsage();
		}
	}
}
